var clickListener, map = new AMap.Map("container", {
    rotateEnable: true,
    pitchEnable: true,
    zoom: 19,
    pitch: 50,
    rotation: -15,
    viewMode: '3D', //开启3D视图,默认为关闭
    zooms: [2, 20],
    center: [106.570157,29.535133],
    mapStyle: 'amap://styles/fresh', //设置地图的显示样式

});
/*---------------------------------------------------------------------------------------*/

//地图点击添加标记，显示经纬度
function print_gis() {
    clickListener = function (e) {
        new AMap.Marker({
            position: e.lnglat,
            map: map
        });
        //构建自定义信息窗体
        var infoWindow = new AMap.InfoWindow({
            anchor: 'top-left',
            content: '[' + e.lnglat + '],',
        });

        infoWindow.open(map, e.lnglat);
    };
    map.on("click", clickListener);// 点击地图显示经纬度控制
}



/*---------------------------------------------------------------------------------------*/

var controlBar = new AMap.ControlBar({
    position: {
        right: '10px',
        top: '10px'
    }
});
controlBar.addTo(map);
/*---------------------------------------------------------------------------------------*/

var toolBar = new AMap.ToolBar({
    position: {
        right: '40px',
        top: '110px'
    }
});
toolBar.addTo(map);
/*---------------------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------------------*/

//信息提示
function print(l, a, c) {
    var position = [l, a];

    //构建自定义信息窗体
    var infoWindow = new AMap.InfoWindow({
        anchor: 'top-left',
        content: c,
    });

    infoWindow.open(map, position);

    new AMap.Marker({ position: position, map });
}

/*---------------------------------------------------------------------------------------*/
//加载立体提示牌

function tips_3D() {
    var loca = new Loca.Container({
        map,
    });

    var geo = new Loca.GeoJSONSource({
        data: {
            "type": "FeatureCollection",
            "features": [{
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [108.571128, 31.028474],
                },
                "properties": {
                    "name": "家",
                    "price": 65000,
                    "count": 92
                }
            }
            ]
        }
    })

    // 文字主体图层
    var zMarker = new Loca.ZMarkerLayer({
        loca: loca,
        zIndex: 120,
        depth: false,
    });
    zMarker.setSource(geo);
    zMarker.setStyle({
        content: (i, feat) => {
            var props = feat.properties;
            var leftColor = props.price < 60000 ? 'rgba(0, 28, 52, 0.6)' : 'rgba(33,33,33,0.6)';
            var rightColor = props.price < 60000 ? '#038684' : 'rgba(172, 137, 51, 0.3)';
            var borderColor = props.price < 60000 ? '#038684' : 'rgba(172, 137, 51, 1)';
            return (
                '<div style="width: 490px; height: 228px; padding: 0 0;">' +
                '<p style="display: block; height:80px; line-height:80px;font-size:40px;background-image: linear-gradient(to right, '
                + leftColor + ',' + leftColor + ',' + rightColor + ',rgba(0,0,0,0.4)); border:4px solid '
                + borderColor + '; color:#fff; border-radius: 15px; text-align:center; margin:0; padding:5px;">' +
                props['name'] +
                ': ' +
                (props['price'] / 10000) +
                '</p><span style="width: 130px; height: 130px; margin: 0 auto; display: block; background: url(https://a.amap.com/Loca/static/loca-v2/demos/images/prism_'
                + (props['price'] < 60000 ? 'blue' : 'yellow') + '.png);"></span></div>'
            );
        },
        unit: 'meter',
        rotation: 0,
        alwaysFront: true,
        size: [100 / 2, 60 / 2],
        altitude: 0,
    });

    // 浮动三角
    /*
    var triangleZMarker = new Loca.ZMarkerLayer({
        loca: loca,
        zIndex: 119,
        depth: false,
    });
    triangleZMarker.setSource(geo);
    triangleZMarker.setStyle({
        content: (i, feat) => {
            return (
                '<div style="width: 120px; height: 120px; background: url(https://a.amap.com/Loca/static/loca-v2/demos/images/triangle_'
                + (feat.properties.price < 60000 ? 'blue' : 'yellow')
                + '.png);"></div>'
            );
        },
        unit: 'meter',
        rotation: 0,
        alwaysFront: true,
        size: [60, 60],
        altitude: 15,
    });
    triangleZMarker.addAnimate({
        key: 'altitude',
        value: [0, 1],
        random: true,
        transform: 1000,
        delay: 2000,
        yoyo: true,
        repeat: 999999,
    });*/

    loca.animate.start();
}



//tips_3D()//加载3D提示
//print(108.568349609375,31.033676486546, '这里是半山')
//print_gis()//点击地图显示经纬度